import java.io.File;
import java.io.IOException;
import java.util.Scanner;

//ɨ��ָ��Ŀ¼�����ҵ�����ָ�����������ͨ�ļ���������Ŀ¼�������Һ���ѯ���û��ܷ�ɾ�����ļ�
public class IOTest1 {
    public static void main(String[] args) throws IOException {

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要删除的目录");
        File rootPath = new File(scanner.next());
        System.out.println("请输入要删除的文件名");
        String deleteName = scanner.next();


        //�ж�Ŀ¼�Ƿ���Ч
        if (!rootPath.isDirectory()){
            System.out.println("给出的目录错误");
            return;
        }
        //������ȣ��������Ŀ¼
        scanDir(rootPath, deleteName);
    }

    public static void scanDir(File currentDir,String deleteName){
        //�ҵ����Ŀ¼
        File[] files = currentDir.listFiles();
        if (files == null || files.length == 0){
            return;
        }
        for (File s : files){
            System.out.println(currentDir.getAbsolutePath());
            if (s.isFile()){
                dealDir(s, deleteName);
            }else {
                scanDir(s ,deleteName);
            }
        }

    }

    public static void dealDir(File file, String deleteName){
        //�ж��ǲ�������ļ���
        if (file.getName().equals(deleteName)){
            Scanner scanner = new Scanner(System.in);
            System.out.println("你要删除的是" + file.getAbsolutePath() + "是否要删除");
            String res = scanner.next();
            if (res.equals("Y") || res.equals("y")){
                file.delete();
            }
        }

        return;


    }


}
